#include <REGX52.H>

sbit LCD_E = P2^7;
sbit RS = P2^6;
sbit RW = P2^5;

#define DataPort P0

void Delay100us()		//@11.0592MHz
{
	unsigned char i, j;

	i = 2;
	j = 100;
	do
	{
		while (--j);
	} while (--i);
}

//写命令
void Write_CMD( unsigned char cmd)
{
	RW = 0;
	RS = 0;
	DataPort = cmd;
	LCD_E = 1;
	Delay100us();
	LCD_E = 0;
	Delay100us();
}

//写数据
void Write_Dat(unsigned char Data)
{
	RW = 0;
	RS = 1;
	DataPort = Data;
	LCD_E = 1;
	Delay100us();
	LCD_E = 0;
	Delay100us();
}

void Init(void)
{
	Write_CMD(0x38);//八位数据接口,两行显示，5*7点阵
	Write_CMD(0x0C);//显示开，光标关，闪烁关
	Write_CMD(0x06);//数据读写操作后，光标自动+1，画面不动
	Write_CMD(0x01);//clear
}

void ShowChar(unsigned char Line,unsigned char Colunm,unsigned char Char) 
{
	if(Line == 1)
	{
		Write_CMD(0x80 | (Colunm-1));
	}
	else
	{
		Write_CMD(0x80 | (Colunm-1) + 0x40);
	}
	Write_Dat(Char);
}